import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class TabViewPage01 extends StatefulWidget {
  const TabViewPage01({Key? key}) : super(key: key);

  @override
  _TabViewPageState01 createState() => _TabViewPageState01();
}

class _TabViewPageState01 extends State<TabViewPage01>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;
  List<String> tabs = ["新闻", "历史", "图片"];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(length: tabs.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Tab View Page01"),
        bottom: TabBar(
          controller: _tabController,
          tabs: tabs
              .map((e) => Tab(
                    text: e,
                  ))
              .toList(),
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: tabs.map(
          (e) {
            return KeepAlive(
              keepAlive: true,
              child: Container(
                alignment: Alignment.center,
                child: Text(
                  e,
                  textScaleFactor: 5,
                ),
              ),
            );
          },
        ).toList(),
      ),
    );
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }
}
